﻿@model IList<XCode.Membership.Menu>
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@{
    var fact = ViewBag.Factory as IEntityOperate;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as IList<FieldItem>;
        var set = ViewBag.PageSetting as PageSetting;
    //var provider = ManageProvider.Provider;
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            @if (set.EnableSelect)
            {
                <th class="text-center" style="width:10px;"><input type="checkbox" id="chkAll" title="全选" /></th>
            }
            <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("TreeNodeName"))">节点名</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("DisplayName"))">显示名</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Url"))">链接</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Sort"))">排序</a></th>
            @*<th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Icon"))">图标</a></th>*@
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Visible"))">可见</a></th>
            <th class="text-center" title="必要。必要的菜单，必须至少有角色拥有这些权限，如果没有则自动授权给系统角色"><a href="@Html.Raw(page.GetSortUrl("Necessary"))">必要</a></th>
            <th class="text-center" title="权限子项。逗号分隔，每个权限子项名值竖线分隔"><a href="@Html.Raw(page.GetSortUrl("Permission"))">权限子项</a></th>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <th class="text-center">升</th>
                <th class="text-center">降</th>
                <th class="text-center" style="min-width:100px;">操作</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var entity in Model)
        {
            var p = entity.Parent as IEntityTree;
            if (p == null)
            {
                p = fact.EntityType.GetValue("Root") as IEntityTree;
            }
            var id = entity.ID;
            <tr>
                @if (set.EnableSelect)
                {
                    <td class="text-center"><input type="checkbox" name="keys" value="@entity.ID" /></td>
                }
                <td class="text-center hidden-md hidden-sm hidden-xs">@entity.ID</td>
                <td>@entity.TreeNodeName</td>
                <td>@entity.DisplayName</td>
                <td>@entity.Url</td>
                <td class="text-right">@entity.Sort.ToString("n0")</td>
                @*<td>@entity.Icon</td>*@
                <td class="text-center">
                    <i class="glyphicon glyphicon-@(entity.Visible ? "ok" : "remove")" style="color: @(entity.Visible ? "green" : "red");"></i>
                </td>
                <td class="text-center">
                    <i class="glyphicon glyphicon-@(entity.Necessary ? "ok" : "remove")" style="color: @(entity.Necessary ? "green" : "red");"></i>
                </td>
                <td>@entity.Permission</td>
                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <td class="text-center">
                        @if (p != null && p.Childs != null && p.Childs.Count > 0 && entity != p.Childs[0])
                        {
                            <a href="@Url.Action("Up", new { id })"><span class="glyphicon glyphicon-arrow-up" style="color: green;"></span></a>
                        }
                    </td>
                    <td class="text-center">
                        @if (p != null && entity != p.Childs[p.Childs.Count - 1])
                        {
                            <a href="@Url.Action("Down", new { id })"><span class="glyphicon glyphicon-arrow-down" style="color: red;"></span></a>
                        }
                    </td>
                    <td class="text-center">
                        @Html.PartialAsync("_List_Data_Action", (Object)entity).Result
                    </td>
                }
            </tr>
        }
    </tbody>
</table>